package com.ivncorp.evnproject.helpers;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;
import android.os.Environment;
import android.util.Log;


public class SetupPhotos {
	
	private static final String JPEG_FILE_PREFIX = "IMG_";
	private static final String JPEG_FILE_SUFFIX = ".jpg";
	private AlbumStorageDirFactory mAlbumStorageDirFactory = null;
	//private String mCurrentPhotoPath = "";
	
	public SetupPhotos(){
		mAlbumStorageDirFactory=new AlbumStorageDirFactory();
	}
	
	private String getAlbumName() {
		return AppConstant.PHOTO_ALBUM;
	}

	private File getAlbumDir() {
		File storageDir = null;

		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {

			storageDir = mAlbumStorageDirFactory
					.getAlbumStorageDir(getAlbumName());

			if (storageDir != null) {
				if (!storageDir.mkdirs()) {
					if (!storageDir.exists()) {
						Log.d(AppConstant.PHOTO_ALBUM,
								"failed to create directory");
						return null;
					}
				}
			}

		} /*else {
			Log.v(getString(R.string.app_name),
					"External storage is not mounted READ/WRITE.");
		}*/

		return storageDir;
	}

	@SuppressLint("SimpleDateFormat")
	public File createImageFile() throws IOException {
		// Create an image file name
		String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
				.format(new Date());
		String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";
		File albumF = getAlbumDir();
		File imageF = File.createTempFile(imageFileName, JPEG_FILE_SUFFIX,
				albumF);
		return imageF;
	}

	
}
